﻿using CommunityToolkit.Mvvm.ComponentModel;
using GameView.Comment;
using GameView.Models;
using GameView.Services.Dtos;
using GameView.Services.Dtos.WithdrawalDto;

namespace GameView.Services
{
    public partial class WithdrawalService : ObservableObject
    {
        [ObservableProperty]
        private bool _isLoading;

        public async Task<ApiResponse<int>> UpdateAsync(WithdrawalEditDto id)
        {
            IsLoading = true;
            var res = await $"{APIHelper.Withdrawal}/edit".PutAsync<int, WithdrawalEditDto>(id);
            IsLoading = false;
            return res;
        }

        public async Task<ApiResponse<PagedList<WithdrawalRecords>>> GetPageAsync(WithdrawalQueryDto id)
        {
            if (id.EndTime.IsNullOrEmpty())
                id.EndTimeDT = DateTime.Now.ToStringMax();
            if (id.StartTime.IsNullOrEmpty())
                id.StartTimeDT = DateTime.Now.AddHours(-24).ToStringMin();
            IsLoading = true;
            var res = await $"{APIHelper.Withdrawal}/by-page".PostAsync<PagedList<WithdrawalRecords>, WithdrawalQueryDto>(id);
            IsLoading = false;
            return res;
        }

        public async Task<ApiResponse<List<long>>> GetSTAsync(WithdrawalQueryDto id)
        {
            if (id.EndTime.IsNullOrEmpty())
                id.EndTimeDT = DateTime.Now.ToStringMax();
            if (id.StartTime.IsNullOrEmpty())
                id.StartTimeDT = DateTime.Now.AddHours(-24).ToStringMin();
            IsLoading = true;
            var rr = JSON.Serialize(id);
            var res = await $"{APIHelper.Withdrawal}/by-st".PostAsync<List<long>, WithdrawalQueryDto>(id);
            IsLoading = false;
            return res;
        }
    }
}